import express from "express";
import dotenv from 'dotenv'

// 加载环境变量
dotenv.config()

import { userAuth } from "./middlewares/user-auth";
import usersRouter from './routes/users'
import authRouter from './routes/auth'
import uploadsRouter from './routes/uploads'
import categoriesRouter from './routes/categories'
import articlesRouter from './routes/articles'
import postsRouter from './routes/posts'
import commentsRouter from './routes/comments'
import likesRouter from './routes/likes'
import collectsRouter from './routes/collects'
import sharesRouter from './routes/shares'
import followRouter from './routes/follow'
import dynamicRouter from './routes/dynamic'
import examsRouter from './routes/exams'
import searchRouter from './routes/search'

// 创建和设置Express应用程序
const app = express();

app.use(express.json());
app.use(express.urlencoded({ extended: false }));

// 前台路由配置
app.use('/user', userAuth, usersRouter);
app.use('/auth', authRouter);
app.use('/common', userAuth, uploadsRouter);
app.use('/category', userAuth, categoriesRouter);
app.use('/article', userAuth, articlesRouter);
app.use('/post', userAuth, postsRouter);
app.use('/comment', userAuth, commentsRouter);
app.use('/like', userAuth, likesRouter);
app.use('/collect', userAuth, collectsRouter);
app.use('/share', userAuth, sharesRouter);
app.use('/follow', userAuth, followRouter);
app.use('/dynamic', userAuth, dynamicRouter);
app.use('/exam', userAuth, examsRouter);
app.use('/search', userAuth, searchRouter);

export default app